//
//  ReadListViewController.m
//  Lianxi2
//
//  Created by lanou on 16/7/5.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ReadListViewController.h"

@interface ReadListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableview;
@property (nonatomic,strong)NSMutableArray *datasource;

@end

@implementation ReadListViewController
- (NSMutableArray *)datasource{
    if (!_datasource) {
        _datasource = [NSMutableArray array];
    }
    return _datasource;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    [RequestManager fetchDataWithURL:KReadListUrl parameter:@{@"typeid":@27} metod:@"POST" compelet:^(NSData *data) {
        //请求数据，分析数据，建立模型，添加数组
        NSDictionary *bigDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        NSLog(@"%@",bigDic);
        for (NSDictionary *smallDic in bigDic[@"data"][@"list"]) {
            ReadListModel *model = [[ReadListModel alloc]init];
            [model setValuesForKeysWithDictionary:smallDic];
            [self.datasource addObject:model];
        }
        
    } updateUI:^{
        [self.tableview reloadData];
    }];
    
    [self.tableview registerNib:[UINib nibWithNibName:@"ReadlistTableViewCell" bundle:nil] forCellReuseIdentifier:@"readlistcell"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.datasource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ReadListModel *model = self.datasource[indexPath.row];
    ReadlistTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"readlistcell" forIndexPath:indexPath];
    [cell setCellWithModel:model];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
